home *** CD-ROM | disk | FTP | other *** search
/ mail.altrad.com / 2015.02.mail.altrad.com.tar / mail.altrad.com / TEST / office german / PROPLUS.WW / PROPLSWW.CAB / sql2000.xsl.5DF9D670_534C_4AB2_B0C6_FF0B0C448C29 < prev    next >
Extensible Markup Language  |  2006-10-26  |  33KB  |  766 lines

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" xmlns:mssqlcrt="urn:sql-microsoft-com:sqlcrt" xmlns:mssqldbg="urn:sql-microsoft-com:sqldbg">
  3.     <xsl:output method="xml" indent="yes"/>
  4.  
  5.     <!-- This ALWAYS GENERATED file contains the definitions for the cartridges
  6.                  Microsoft Cartridge Interfaces (Analysis Services 2005)
  7.                  (C) Copyright 1988 - 2003 By Microsoft Corporation.      -->
  8.  
  9.     <!-- SQL Server 2000 pluggable cartridge                              -->
  10.  
  11.     <!-- Area of STANDARD parametrizations: these are externally passed   -->
  12.     <xsl:param name="in_CanUseParams">yes</xsl:param>
  13.     <xsl:param name="in_IdentStartQuotingCharacter">[</xsl:param>
  14.     <xsl:param name="in_IdentEndQuotingCharacter">]</xsl:param>
  15.     <xsl:param name="in_StringStartQuotingCharacter">N'</xsl:param>
  16.     <xsl:param name="in_StringEndQuotingCharacter">'</xsl:param>
  17.     
  18.     <!-- Area of CORE parametrizations: These are externally checked      -->
  19.     <mssqlcrt:provider>Microsoft SQL Server.08.00.0191</mssqlcrt:provider>
  20.     <mssqlcrt:provider>Microsoft SQL Server.08.00.0194</mssqlcrt:provider>
  21.     <mssqlcrt:provider type="prefix">Microsoft SQL Server</mssqlcrt:provider>
  22.     <mssqlcrt:provider type="prefix"></mssqlcrt:provider>
  23.  
  24.     <mssqlcrt:capabilities>
  25.         <mssqlcrt:supports-datepart-year/>
  26.         <mssqlcrt:supports-datepart-quarter/>
  27.         <mssqlcrt:supports-datepart-month/>
  28.         <mssqlcrt:supports-datepart-dayofyear/>
  29.         <mssqlcrt:supports-datepart-day/>
  30.         <mssqlcrt:supports-datepart-week/>
  31.         <mssqlcrt:supports-datepart-dayofweek/>
  32.         <mssqlcrt:supports-datepart-hour/>
  33.         <mssqlcrt:supports-datepart-minute/>
  34.         <mssqlcrt:supports-datepart-second/>
  35.         <mssqlcrt:supports-datepart-millisecond/>
  36.         <mssqlcrt:supports-multiple-distinct-count/>
  37.         <mssqlcrt:supports-update/>
  38.         <mssqlcrt:supports-insert/>
  39.         <mssqlcrt:supports-subselect/>
  40.         <mssqlcrt:supports-table-alias/>
  41.         <mssqlcrt:supports-column-alias/>
  42.         <mssqlcrt:supports-cast/>
  43.         <mssqlcrt:supports-remote-query/>
  44.         <mssqlcrt:supports-top-clause/>
  45.         <mssqlcrt:supports-union/>
  46.         <mssqlcrt:supports-union-all/>
  47.         <mssqlcrt:supports-fast-writeback>TABLOCK,FIRE_TRIGGERS</mssqlcrt:supports-fast-writeback>
  48.         <mssqlcrt:supports-materialized-view>2</mssqlcrt:supports-materialized-view>
  49.         <!-- mssqlcrt:supports-materialized-view-prevalidation -->
  50.  
  51.         <mssqlcrt:limit-materialized-view-column-count>16</mssqlcrt:limit-materialized-view-column-count>
  52.         <!--
  53.             This cartridge is used as the default cartridge for unknown providers
  54.             So even though SQL supports larger aliases (at least 128), we'll use a smaller
  55.             alias for the other providers
  56.         -->
  57.         <mssqlcrt:limit-table-identifier-length>64</mssqlcrt:limit-table-identifier-length>
  58.         <mssqlcrt:limit-column-identifier-length>64</mssqlcrt:limit-column-identifier-length>
  59.  
  60.         <!-- Map from MSDAInitialize connection string to SQLOLEDB connection string -->
  61.         <mssqlcrt:remote-connection-string-mappings>
  62.             <mssqlcrt:remote-connection-string-mapping>
  63.                 <mssqlcrt:datasource-property>Provider</mssqlcrt:datasource-property>
  64.                 <mssqlcrt:remote-property></mssqlcrt:remote-property>
  65.             </mssqlcrt:remote-connection-string-mapping>
  66.             <mssqlcrt:remote-connection-string-mapping>
  67.                 <mssqlcrt:datasource-property>Data Source</mssqlcrt:datasource-property>
  68.                 <mssqlcrt:remote-property>Server</mssqlcrt:remote-property>
  69.             </mssqlcrt:remote-connection-string-mapping>
  70.             <mssqlcrt:remote-connection-string-mapping>
  71.                 <mssqlcrt:datasource-property>Initial Catalog</mssqlcrt:datasource-property>
  72.                 <mssqlcrt:remote-property>Database</mssqlcrt:remote-property>
  73.             </mssqlcrt:remote-connection-string-mapping>
  74.             <mssqlcrt:remote-connection-string-mapping>
  75.                 <mssqlcrt:datasource-property>User ID</mssqlcrt:datasource-property>
  76.                 <mssqlcrt:remote-property>UID</mssqlcrt:remote-property>
  77.             </mssqlcrt:remote-connection-string-mapping>
  78.             <mssqlcrt:remote-connection-string-mapping>
  79.                 <mssqlcrt:datasource-property>Password</mssqlcrt:datasource-property>
  80.                 <mssqlcrt:remote-property>PWD</mssqlcrt:remote-property>
  81.             </mssqlcrt:remote-connection-string-mapping>
  82.             <mssqlcrt:remote-connection-string-mapping>
  83.                 <mssqlcrt:datasource-property>Integrated Security=SSPI</mssqlcrt:datasource-property>
  84.                 <mssqlcrt:remote-property>Trusted_Connection=yes</mssqlcrt:remote-property>
  85.             </mssqlcrt:remote-connection-string-mapping>
  86.         </mssqlcrt:remote-connection-string-mappings>
  87.     </mssqlcrt:capabilities>
  88.  
  89.     <mssqlcrt:schema-classes>
  90.         <mssqlcrt:schema-class>
  91.             <mssqlcrt:managed-provider>System.Data.SqlClient</mssqlcrt:managed-provider>
  92.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.SqlSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  93.             <mssqlcrt:query-designer>
  94.                 <mssqlcrt:type>Microsoft.DataWarehouse.Controls.SqlClientQueryDesigner, Microsoft.DataWarehouse</mssqlcrt:type>
  95.             </mssqlcrt:query-designer>
  96.         </mssqlcrt:schema-class>
  97.         <mssqlcrt:schema-class>
  98.             <mssqlcrt:managed-provider>System.Data.OleDb</mssqlcrt:managed-provider>
  99.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OleDbSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  100.             <mssqlcrt:query-designer>
  101.                 <mssqlcrt:type>Microsoft.DataWarehouse.Controls.OleDbQueryDesigner, Microsoft.DataWarehouse</mssqlcrt:type>
  102.             </mssqlcrt:query-designer>
  103.         </mssqlcrt:schema-class>
  104.         <mssqlcrt:schema-class>
  105.             <mssqlcrt:managed-provider>System.Data.Odbc</mssqlcrt:managed-provider>
  106.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OdbcSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  107.         </mssqlcrt:schema-class>
  108.     </mssqlcrt:schema-classes>
  109.     <!-- Area of internal parametrizations                                -->
  110.     <!-- overrideOfUseParams:
  111.              yes      = use always parametric queries
  112.              no       = never use parametric queries
  113.              nosubsel = use as yes, but not on subselects
  114.              auto     = use the value of in_CanUseParams to determine     -->
  115.     <xsl:variable name="overrideOfUseParams">auto</xsl:variable>
  116.     <!-- shouldProduceDebug:
  117.              yes      = produce debug information
  118.              no       = do not produce debug information                  -->
  119.     <xsl:variable name="shouldProduceDebug">yes</xsl:variable>
  120.  
  121.     <!-- Area of global variables initializations                         -->
  122.     <xsl:variable name="UseParams">
  123.         <xsl:choose>
  124.             <xsl:when test="normalize-space($overrideOfUseParams) = 'yes' or (normalize-space($overrideOfUseParams) = 'auto' and normalize-space($in_CanUseParams)='yes')">yes</xsl:when>
  125.             <xsl:when test="normalize-space($overrideOfUseParams) = 'nosubsel'">nosubsel</xsl:when>
  126.             <xsl:otherwise>no</xsl:otherwise>
  127.         </xsl:choose>
  128.     </xsl:variable>
  129.     <xsl:variable name="ProduceDebug" select="$shouldProduceDebug"/>
  130.     <xsl:variable name="IdentifierStartQuotingCharacter" select="normalize-space($in_IdentStartQuotingCharacter)"/>
  131.     <xsl:variable name="IdentifierEndQuotingCharacter" select="normalize-space($in_IdentEndQuotingCharacter)"/>
  132.     <xsl:variable name="StringStartQuotingCharacter" select="normalize-space($in_StringStartQuotingCharacter)"/>
  133.     <xsl:variable name="StringEndQuotingCharacter" select="normalize-space($in_StringEndQuotingCharacter)"/>
  134.  
  135.     <!-- Generated statement packaging                                    -->
  136.     <xsl:template match="/">
  137.         <xsl:element name="Statement">
  138.  
  139.             <!-- Generate query                                           -->
  140.             <xsl:element name="Text">
  141.                 <xsl:apply-templates select="./Statement/*[1]"/>
  142.             </xsl:element>
  143.  
  144.             <!-- Generate parameters                                      -->
  145.             <xsl:if test="count(./Statement/Parameters/Parameter)!=0 and ((normalize-space($UseParams)='yes') or (normalize-space($UseParams)='nosubsel'))">
  146.                 <xsl:element name="Parameters">
  147.                     <xsl:choose>
  148.                         <xsl:when test="/Statement/*[1]//Parameter/@ParamName">
  149.                             <xsl:for-each select="./Statement/Parameters/Parameter">
  150.                                 <xsl:element name="Parameter">
  151.                                     <xsl:attribute name="ref">
  152.                                         <xsl:value-of select="./@id"/>
  153.                                     </xsl:attribute>
  154.                                 </xsl:element>
  155.                             </xsl:for-each>
  156.                         </xsl:when>
  157.                         <xsl:otherwise>
  158.                             <xsl:for-each select="./Statement/*[1]//Parameter">
  159.                                 <xsl:element name="Parameter">
  160.                                     <xsl:attribute name="ref">
  161.                                         <xsl:value-of select="./@ref"/>
  162.                                     </xsl:attribute>
  163.                                 </xsl:element>
  164.                             </xsl:for-each>
  165.                         </xsl:otherwise>
  166.                     </xsl:choose>
  167.                 </xsl:element>
  168.             </xsl:if>
  169.  
  170.             <!-- Generate debug info                                      -->
  171.             <xsl:if test="$ProduceDebug='yes'">
  172.                 <xsl:element name="mssqldbg:DebugInfo">
  173.                     <xsl:element name="mssqldbg:GenerateParametricInfo">
  174.                         <xsl:attribute name="mssqldbg:Value">
  175.                             <xsl:value-of select="$UseParams"/>
  176.                         </xsl:attribute>
  177.                         <xsl:element name="mssqldbg:External">
  178.                             <xsl:value-of select="$in_CanUseParams"/>
  179.                         </xsl:element>
  180.                         <xsl:element name="mssqldbg:Internal">
  181.                             <xsl:value-of select="$overrideOfUseParams"/>
  182.                         </xsl:element>
  183.                     </xsl:element>
  184.                 </xsl:element>
  185.             </xsl:if>
  186.  
  187.         </xsl:element>
  188.     </xsl:template>
  189.  
  190.     <!-- Union statement                                                  -->
  191.     <xsl:template match="Union">
  192.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  193.             (
  194.         </xsl:if>
  195.             <xsl:call-template name="print-children-list">
  196.                 <xsl:with-param name="operator" select="' UNION '"/>
  197.             </xsl:call-template>
  198.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  199.             )
  200.         </xsl:if>
  201.     </xsl:template>
  202.  
  203.     <!-- Union All statement                                                  -->
  204.     <xsl:template match="UnionAll">
  205.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  206.             (
  207.         </xsl:if>
  208.             <xsl:call-template name="print-children-list">
  209.                 <xsl:with-param name="operator" select="' UNION ALL '"/>
  210.             </xsl:call-template>
  211.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  212.             )
  213.         </xsl:if>
  214.     </xsl:template>
  215.  
  216.     <!-- Top clause                                                       -->
  217.     <xsl:template match="Top">
  218.         TOP <xsl:value-of select="."/><xsl:text> </xsl:text>
  219.     </xsl:template>
  220.  
  221.     <!-- Select statement                                                 -->
  222.     <xsl:template match="Select">
  223.         <xsl:choose>
  224.             <xsl:when test="count(./ColumnExpressions/IsValidForIndexing) != 0">
  225.                 SELECT OBJECTPROPERTY( object_id('<xsl:apply-templates select="./Sources/View"/>'), 'isindexable' )
  226.             </xsl:when>
  227.             <xsl:otherwise>
  228.                 <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  229.                     (
  230.                 </xsl:if>
  231.                 SELECT <xsl:apply-templates select="./Top"/>
  232.                     <xsl:apply-templates select="./Distinct"/>
  233.                     <xsl:apply-templates select="./ColumnExpressions"/>
  234.                     <xsl:if test="count(../Phase) != 0">, COUNT_BIG(*) AS [COUNT_BIG_7673aff6-2445-4ef6-a4c9-7bf3d93bd42a] </xsl:if>
  235.                     <xsl:apply-templates select="./Sources"/>
  236.                     <xsl:apply-templates select="./Where"/>
  237.                     <xsl:apply-templates select="./GroupBy"/>
  238.                     <xsl:apply-templates select="./Having"/>
  239.                     <xsl:apply-templates select="./OrderBy"/>
  240.                 <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  241.                     )
  242.                 </xsl:if>
  243.             </xsl:otherwise>
  244.         </xsl:choose>
  245.     </xsl:template>
  246.  
  247.     <!-- Update statement                                                 -->
  248.     <xsl:template match="Update">
  249.         UPDATE <xsl:apply-templates select="./Target"/>
  250.             <xsl:apply-templates select="./Where"/>
  251.     </xsl:template>
  252.  
  253.     <!-- Insert statement                                                 -->
  254.     <xsl:template match="Insert">
  255.         INSERT INTO <xsl:apply-templates select="./Target"/>
  256.         <xsl:apply-templates select="./Select"/>
  257.     </xsl:template>
  258.  
  259.     <!-- Delete statement                                                 -->
  260.     <xsl:template match="Delete">
  261.         DELETE FROM <xsl:apply-templates select="./Target"/>
  262.             <xsl:apply-templates select="./Where"/>
  263.     </xsl:template>
  264.  
  265.     <!-- Drop statement                                                   -->
  266.     <xsl:template match="Drop">
  267.         DROP <xsl:apply-templates select="./*"/>
  268.     </xsl:template>
  269.  
  270.     <!-- Create statement                                                 -->
  271.     <xsl:template match="Create">
  272.         CREATE 
  273.         <xsl:variable name="phase"><xsl:value-of select="./Phase"/></xsl:variable>
  274.         <xsl:choose>
  275.             <xsl:when test="number($phase)=1">
  276.                 VIEW <xsl:apply-templates select="./View"/> ( <xsl:apply-templates select="./*[4]"/>, [COUNT_BIG_7673aff6-2445-4ef6-a4c9-7bf3d93bd42a] ) WITH SCHEMABINDING AS <xsl:apply-templates select="./*[5]"/>
  277.             </xsl:when>
  278.             <xsl:when test="number($phase)=2">
  279.                 UNIQUE CLUSTERED INDEX <xsl:apply-templates select="./Index"/> ON <xsl:apply-templates select="./View"/> ( <xsl:apply-templates select="./*[4]"/> )
  280.             </xsl:when>
  281.             <xsl:otherwise>
  282.                 <xsl:apply-templates select="./*[1]"/>
  283.                 <xsl:choose>
  284.                     <xsl:when test="name(./*[1]) = 'Table'"> ( <xsl:apply-templates select="./*[2]"/> )</xsl:when>
  285.                 </xsl:choose>
  286.             </xsl:otherwise>
  287.         </xsl:choose>
  288.     </xsl:template>
  289.  
  290.     <!-- Remote query (OPENROWSET)                                        -->
  291.     <xsl:template match="RemoteQuery">
  292.         OPENROWSET
  293.         (
  294.             <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./Provider"/></xsl:call-template>,
  295.             <xsl:choose>
  296.                 <xsl:when test="./DataSource">
  297.                     <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./DataSource"/></xsl:call-template>;<xsl:call-template name="quote-string"><xsl:with-param name="string" select="./UserName"/></xsl:call-template>;<xsl:call-template name="quote-string"><xsl:with-param name="string" select="./Password"/></xsl:call-template>,
  298.                 </xsl:when>
  299.                 <xsl:otherwise>
  300.                     <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./ConnectionString"/></xsl:call-template>,
  301.                 </xsl:otherwise>
  302.             </xsl:choose>
  303.             <xsl:call-template name="quote-string"><xsl:with-param name="string" select="./*[last()]"/></xsl:call-template>
  304.         )
  305.     </xsl:template>
  306.  
  307.     <xsl:template match="Distinct">
  308.         DISTINCT
  309.     </xsl:template>
  310.  
  311.     <xsl:template match="As">
  312.         <xsl:apply-templates select="./*[1]"/> AS <xsl:apply-templates select="./*[2]"/>
  313.     </xsl:template>
  314.  
  315.     <xsl:template match="Sources">
  316.         FROM <xsl:call-template name="print-children-list"/>
  317.     </xsl:template>
  318.  
  319.     <xsl:template match="ColumnDefinitions">
  320.         <xsl:call-template name="print-children-list"/>
  321.     </xsl:template>
  322.  
  323.     <xsl:template match="GroupBy">
  324.         GROUP BY <xsl:call-template name="print-children-list"/>
  325.     </xsl:template>
  326.  
  327.     <xsl:template match="OrderBy">
  328.         ORDER BY <xsl:call-template name="print-children-list"/>
  329.     </xsl:template>
  330.  
  331.     <xsl:template match="Where">
  332.         WHERE <xsl:apply-templates select="./*"/>
  333.     </xsl:template>
  334.  
  335.     <xsl:template match="Having">
  336.         HAVING <xsl:apply-templates select="./*"/>
  337.     </xsl:template>
  338.  
  339.     <xsl:template match="ColumnExpressions">
  340.         <xsl:call-template name="print-children-list"/>
  341.     </xsl:template>
  342.  
  343.     <xsl:template match="ColumnUpdates">
  344.         <xsl:call-template name="print-children-list"/>
  345.     </xsl:template>
  346.  
  347.     <xsl:template match="Assign">
  348.         <xsl:apply-templates select="./*[1]"/>=<xsl:apply-templates select="./*[2]"/>
  349.     </xsl:template>
  350.  
  351.     <xsl:template match="Insert/Target">
  352.         <xsl:apply-templates select="./Table"/>
  353.         (
  354.             <xsl:call-template name="print-list">
  355.                 <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[1]"/>
  356.             </xsl:call-template>
  357.         )
  358.         <xsl:if test="./*[2]/Assign">
  359.             VALUES
  360.             (
  361.                 <xsl:call-template name="print-list">
  362.                     <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[2]"/>
  363.                 </xsl:call-template>
  364.             )
  365.         </xsl:if>
  366.     </xsl:template>
  367.  
  368.     <xsl:template match="Update/Target">
  369.         <xsl:apply-templates select="./Table"/>
  370.         SET <xsl:apply-templates select="./ColumnUpdates"/>
  371.     </xsl:template>
  372.  
  373.     <xsl:template match="Delete/Target">
  374.         <xsl:apply-templates select="./Table"/>
  375.     </xsl:template>
  376.  
  377.     <xsl:template match="Insert/Target/ColumnUpdates/Assign/SQLColumn[1]">
  378.         <!-- The table name is not printed for LHS of assignments in insert -->
  379.         <xsl:apply-templates select="./Column"/>
  380.     </xsl:template>
  381.  
  382.     <xsl:template match="Create/ColumnDefinitions/SQLColumn">
  383.         <xsl:apply-templates select="./Column"/>
  384.         <xsl:if test="count(../../Phase) = 0">
  385.             <xsl:apply-templates select="./Type"/>
  386.             <xsl:apply-templates select="./Usage"/>
  387.         </xsl:if>
  388.     </xsl:template>
  389.  
  390.     <xsl:template match="SQLColumn">
  391.         <xsl:variable name="table">
  392.             <xsl:if test="name(..)!='Count' or name(./Column/*[1]) != 'Asterisk'"><xsl:apply-templates select="./Table"/></xsl:if>
  393.         </xsl:variable>
  394.         <xsl:variable name="column">
  395.             <xsl:apply-templates select="./Column"/>
  396.         </xsl:variable>
  397.         <xsl:choose>
  398.             <xsl:when test="$table = ''">
  399.                 <xsl:value-of select="$column"/>
  400.             </xsl:when>
  401.             <xsl:otherwise>
  402.                 <xsl:value-of select="concat($table,'.', $column)"/>
  403.             </xsl:otherwise>
  404.         </xsl:choose>
  405.     </xsl:template>
  406.  
  407.     <xsl:template match="Create/Database|Drop/Database">
  408.         DATABASE <xsl:apply-templates select="./Name"/>
  409.     </xsl:template>
  410.  
  411.     <xsl:template match="Table">
  412.         <xsl:call-template name="build-quoted-schema-object"/>
  413.     </xsl:template>
  414.  
  415.     <xsl:template match="Create/Table|Drop/Table">
  416.         TABLE <xsl:call-template name="build-quoted-schema-object"/>
  417.     </xsl:template>
  418.  
  419.     <xsl:template match="View">
  420.         <xsl:call-template name="build-quoted-schema-object"/>
  421.     </xsl:template>
  422.  
  423.     <xsl:template match="Drop/View">
  424.         VIEW <xsl:call-template name="build-quoted-schema-object"/>
  425.     </xsl:template>
  426.  
  427.     <xsl:template match="Index">
  428.         <xsl:apply-templates select="./Name"/>
  429.     </xsl:template>
  430.  
  431.     <xsl:template match="Drop/Index">
  432.         INDEX <xsl:apply-templates select="./Name"/>
  433.     </xsl:template>
  434.  
  435.     <xsl:template match="Column">
  436.         <xsl:apply-templates select="./Asterisk"/>
  437.         <xsl:apply-templates select="./Name"/>
  438.     </xsl:template>
  439.  
  440.     <xsl:template match="Table/Name|View/Name|Index/Name|Column/Name|Database/Name|Schema">
  441.         <xsl:call-template name="quote-identifier"/>
  442.     </xsl:template>
  443.  
  444.     <xsl:template match="Usage">
  445.         <xsl:variable name="usage"><xsl:value-of select="."/></xsl:variable>
  446.         <xsl:choose>
  447.             <xsl:when test="$usage = 'Key'">    primary key   </xsl:when>
  448.         </xsl:choose>
  449.     </xsl:template>
  450.  
  451.     <xsl:template match="OpaqueExpression">
  452.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  453.             (
  454.         </xsl:if>
  455.         <xsl:value-of select="."/>
  456.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  457.             )
  458.         </xsl:if>
  459.     </xsl:template>
  460.  
  461.     <xsl:template match="OrderExpression">
  462.         <xsl:apply-templates select="./*[1]"/>
  463.         <xsl:apply-templates select="./Asc"/>
  464.         <xsl:apply-templates select="./Desc"/>
  465.     </xsl:template>
  466.  
  467.     <xsl:template match="Asc">
  468.         ASC
  469.     </xsl:template>
  470.  
  471.     <xsl:template match="Desc">
  472.         DESC
  473.     </xsl:template>
  474.  
  475.     <!-- Print values: ? for parametric queries and convert expressions
  476.          for non-parametric queries                                       -->
  477.     <xsl:template match="Parameter">
  478.         <xsl:choose>
  479.             <xsl:when test="$UseParams = 'yes' or $UseParams = 'nosubsel'">
  480.                 <xsl:choose>
  481.                     <xsl:when test="./@ParamName">
  482.                         @<xsl:value-of select="./@ParamName"/>
  483.                     </xsl:when>
  484.                     <xsl:otherwise>
  485.                         ?
  486.                     </xsl:otherwise>
  487.                 </xsl:choose>
  488.             </xsl:when>
  489.             <xsl:otherwise>
  490.                 <xsl:call-template name="print-non-parametric-parameter-ref">
  491.                     <xsl:with-param name="parameter-reference" select="."/>
  492.                 </xsl:call-template>
  493.             </xsl:otherwise>
  494.         </xsl:choose>
  495.     </xsl:template>
  496.  
  497.     <!-- DatePart                                                         -->
  498.     <xsl:template match="DatePart">
  499.         DATEPART( <xsl:apply-templates select="./*[1]"/> , <xsl:apply-templates select="./*[2]"/> )
  500.     </xsl:template>
  501.  
  502.     <!-- DatePartSpec                                                     -->
  503.     <xsl:template match="DatePartSpec">
  504.         <xsl:variable name="dps-val"><xsl:value-of select="normalize-space(./text())"/></xsl:variable>
  505.         <xsl:choose>
  506.             <xsl:when test="$dps-val = 'Year'">        year        </xsl:when>
  507.             <xsl:when test="$dps-val = 'Quarter'">     quarter     </xsl:when>
  508.             <xsl:when test="$dps-val = 'Month'">       month       </xsl:when>
  509.             <xsl:when test="$dps-val = 'DayOfYear'">   dayofyear   </xsl:when>
  510.             <xsl:when test="$dps-val = 'Day'">         day         </xsl:when>
  511.             <xsl:when test="$dps-val = 'Week'">        week        </xsl:when>
  512.             <xsl:when test="$dps-val = 'DayOfWeek'">   weekday     </xsl:when>
  513.             <xsl:when test="$dps-val = 'Hour'">        hour        </xsl:when>
  514.             <xsl:when test="$dps-val = 'Minute'">      minute      </xsl:when>
  515.             <xsl:when test="$dps-val = 'Second'">      second      </xsl:when>
  516.             <xsl:when test="$dps-val = 'Millisecond'"> millisecond </xsl:when>
  517.         </xsl:choose>
  518.     </xsl:template>
  519.  
  520.     <!-- Asterisk                                                         -->
  521.     <xsl:template match="Asterisk">*</xsl:template>
  522.  
  523.     <!-- Count/Min/Max/Sum                                                -->
  524.     <xsl:template match="Min|Max|Sum">
  525.         <xsl:variable name="function">
  526.             <xsl:choose>
  527.                 <xsl:when test="name()='Min'"> MIN </xsl:when>
  528.                 <xsl:when test="name()='Max'"> MAX </xsl:when>
  529.                 <xsl:when test="name()='Sum'"> SUM </xsl:when>
  530.             </xsl:choose>
  531.         </xsl:variable>
  532.         <xsl:value-of select="$function"/>( <xsl:apply-templates select="./*[1]"/> )
  533.     </xsl:template>
  534.  
  535.     <xsl:template match="Count">
  536.         COUNT_BIG ( <xsl:apply-templates select="./*[1]"/> <xsl:apply-templates select="./*[2]"/> )
  537.     </xsl:template>
  538.  
  539.     <!-- Binary expressions                                               -->
  540.     <!-- Equal/NotEqual/Greater/GreaterOrEqual/Less/LessOrEqual/In/And/Or/Plus/Minus/Divide/Multiply
  541.          expressions                                                      -->
  542.     <xsl:template match="Equal|NotEqual|Greater|GreaterOrEqual|Less|LessOrEqual|In|And|Or|Plus|Minus|Divide|Multiply">
  543.         <xsl:variable name="operator">
  544.             <xsl:choose>
  545.                 <xsl:when test="name()='Equal'">            =        </xsl:when>
  546.                 <xsl:when test="name()='NotEqual'">            <>    </xsl:when>
  547.                 <xsl:when test="name()='Greater'">            >        </xsl:when>
  548.                 <xsl:when test="name()='GreaterOrEqual'">    >=        </xsl:when>
  549.                 <xsl:when test="name()='Less'">                <    </xsl:when>
  550.                 <xsl:when test="name()='LessOrEqual'">        <=    </xsl:when>
  551.                 <xsl:when test="name()='In'">                IN        </xsl:when>
  552.                 <xsl:when test="name()='And'">                AND        </xsl:when>
  553.                 <xsl:when test="name()='Or'">                OR        </xsl:when>
  554.                 <xsl:when test="name()='Plus'">                +        </xsl:when>
  555.                 <xsl:when test="name()='Minus'">            -        </xsl:when>
  556.                 <xsl:when test="name()='Divide'">            /        </xsl:when>
  557.                 <xsl:when test="name()='Multiply'">            *        </xsl:when>
  558.             </xsl:choose>
  559.         </xsl:variable>
  560.         (
  561.             <xsl:call-template name="print-children-list">
  562.                 <xsl:with-param name="operator" select="$operator"/>
  563.             </xsl:call-template>
  564.         )
  565.     </xsl:template>
  566.  
  567.     <!-- Postfix unary expressions                                        -->
  568.     <!-- IsNull
  569.          expressions                                                      -->
  570.     <xsl:template match="IsNull">
  571.         <xsl:variable name="operator">
  572.             <xsl:choose>
  573.                 <xsl:when test="name()='IsNull'">            IS NULL        </xsl:when>
  574.             </xsl:choose>
  575.         </xsl:variable>
  576.         (
  577.             <xsl:apply-templates select="./*[1]"/>
  578.             <xsl:value-of select="$operator"/>
  579.         )
  580.     </xsl:template>
  581.  
  582.     <!-- Types                                                            -->
  583.     <xsl:template match="Type">
  584.         <xsl:variable name="type-val"><xsl:value-of select="normalize-space(./text())"/></xsl:variable>
  585.         <xsl:choose>
  586.             <xsl:when test="$type-val = 'DBTYPE_BSTR'">    nvarchar     </xsl:when>
  587.             <xsl:when test="$type-val = 'DBTYPE_WSTR'">    nvarchar     </xsl:when>
  588.             <xsl:when test="$type-val = 'DBTYPE_STR'">     varchar      </xsl:when>
  589.             <xsl:when test="$type-val = 'DBTYPE_BOOL'">    bit          </xsl:when>
  590.             <xsl:when test="$type-val = 'DBTYPE_I1'">      tinyint      </xsl:when>
  591.             <xsl:when test="$type-val = 'DBTYPE_I2'">      smallint     </xsl:when>
  592.             <xsl:when test="$type-val = 'DBTYPE_I4'">      int          </xsl:when>
  593.             <xsl:when test="$type-val = 'DBTYPE_I8'">      bigint       </xsl:when>
  594.             <xsl:when test="$type-val = 'DBTYPE_UI1'">     tinyint      </xsl:when>
  595.             <xsl:when test="$type-val = 'DBTYPE_UI2'">     smallint     </xsl:when>
  596.             <xsl:when test="$type-val = 'DBTYPE_UI4'">     int          </xsl:when>
  597.             <xsl:when test="$type-val = 'DBTYPE_UI8'">     bigint       </xsl:when>
  598.             <xsl:when test="$type-val = 'DBTYPE_R4'">      real         </xsl:when>
  599.             <xsl:when test="$type-val = 'DBTYPE_R8'">      float        </xsl:when>
  600.             <xsl:when test="$type-val = 'DBTYPE_DATE'">    datetime     </xsl:when>
  601.             <xsl:when test="$type-val = 'DBTYPE_DBTIMESTAMP'">    datetime     </xsl:when>
  602.             <xsl:when test="$type-val = 'DBTYPE_CY'">      money        </xsl:when>
  603.             <xsl:when test="$type-val = 'DBTYPE_VARIANT'"> sql_variant  </xsl:when>
  604.             <xsl:when test="$type-val = 'DBTYPE_GUID'"> uniqueidentifier  </xsl:when>
  605.             <xsl:when test="$type-val = 'DBTYPE_ByteArray'"> varbinary  </xsl:when>
  606.             <xsl:when test="$type-val = 'DBTYPE_DECIMAL'"> decimal      </xsl:when>
  607.         </xsl:choose>
  608.         <xsl:apply-templates select="./Size"/>
  609.         <xsl:apply-templates select="./Precision"/>
  610.         <xsl:apply-templates select="./Scale"/>        
  611.     </xsl:template>
  612.  
  613.     <!-- Size (optional)                                                  -->
  614.     <xsl:template match="Size">
  615.     ( <xsl:value-of select="./text()"/> )
  616.     </xsl:template>
  617.     
  618.     <!-- Precision (optional)                                                  -->
  619.     <xsl:template match="Precision">
  620.     ( <xsl:value-of select="./text()"/>
  621.     </xsl:template>
  622.  
  623.     <!-- Scale (optional)                                                  -->
  624.     <xsl:template match="Scale">
  625.     , <xsl:value-of select="./text()"/> )
  626.     </xsl:template>
  627.     <!-- Cast                                                             -->
  628.     <xsl:template match="Cast">
  629.         CAST(<xsl:apply-templates select="./*[1]"/> AS <xsl:apply-templates select="./*[2]"/>)
  630.     </xsl:template>
  631.     
  632.     <!-- By default don't do anything                                     -->
  633.     <xsl:template match="*">
  634.     </xsl:template>
  635.  
  636.     <!-- Print a schema object                                               -->
  637.     <xsl:template name="build-quoted-schema-object"> 
  638.         <xsl:param name="schema-object-node" select="."/>
  639.  
  640.         <xsl:variable name="schema">
  641.             <xsl:apply-templates select="$schema-object-node/Schema"/>
  642.         </xsl:variable>
  643.         <xsl:variable name="table">
  644.             <xsl:apply-templates select="$schema-object-node/Name"/>
  645.         </xsl:variable>
  646.         <xsl:choose>
  647.             <xsl:when test="$schema = ''">
  648.                 <xsl:value-of select="$table"/>
  649.             </xsl:when>
  650.             <xsl:otherwise>
  651.                 <xsl:value-of select="concat($schema,'.', $table)"/>
  652.             </xsl:otherwise>
  653.         </xsl:choose>
  654.     </xsl:template>
  655.  
  656.     <!-- Convert an identifier to the OLEDB quotation form                -->
  657.     <xsl:template name="quote-identifier"> 
  658.         <xsl:param name="identifier" select="."/>
  659.  
  660.         <xsl:value-of select="$IdentifierStartQuotingCharacter"/>
  661.         <xsl:call-template name="normalize-entity-aux">
  662.             <xsl:with-param name="entity" select="$identifier"/>
  663.             <xsl:with-param name="end-quoting-char" select="$IdentifierEndQuotingCharacter"/>
  664.         </xsl:call-template>
  665.         <xsl:value-of select="$IdentifierEndQuotingCharacter"/>
  666.     </xsl:template>
  667.  
  668.     <!-- Convert a string to the string quotation form                    -->
  669.     <xsl:template name="quote-string"> 
  670.         <xsl:param name="string" select="."/>
  671.  
  672.         <xsl:value-of select="$StringStartQuotingCharacter"/>
  673.         <xsl:call-template name="normalize-entity-aux">
  674.             <xsl:with-param name="entity" select="$string"/>
  675.             <xsl:with-param name="end-quoting-char" select="$StringEndQuotingCharacter"/>
  676.         </xsl:call-template>
  677.         <xsl:value-of select="$StringEndQuotingCharacter"/>
  678.     </xsl:template>
  679.  
  680.     <!-- Convert an entity to the quotation form (recursive, aux)  by
  681.          duplicating the end quoting character                            -->
  682.     <xsl:template name="normalize-entity-aux"> 
  683.         <xsl:param name="entity"/>
  684.         <xsl:param name="end-quoting-char"/>
  685.  
  686.         <xsl:choose>
  687.             <xsl:when test="contains($entity, $end-quoting-char)">
  688.                 <xsl:value-of select="substring-before($entity, $end-quoting-char)"/>
  689.                 <xsl:value-of select="$end-quoting-char"/>
  690.                 <xsl:value-of select="$end-quoting-char"/>
  691.                 <xsl:call-template name="normalize-entity-aux">
  692.                     <xsl:with-param name="entity" select="substring-after($entity, $end-quoting-char)"/>
  693.                     <xsl:with-param name="end-quoting-char" select="$end-quoting-char"/>
  694.                 </xsl:call-template>
  695.             </xsl:when>
  696.             <xsl:otherwise>
  697.                 <xsl:value-of select="$entity"/>
  698.             </xsl:otherwise>
  699.         </xsl:choose>
  700.     </xsl:template>
  701.  
  702.     <!-- Print the children list                                          -->
  703.     <xsl:template name="print-children-list">
  704.         <xsl:param name="operator" select="','"/>
  705.         
  706.         <xsl:call-template name="print-list">
  707.             <xsl:with-param name="value-node" select="./*"/>
  708.             <xsl:with-param name="operator" select="$operator"/>
  709.         </xsl:call-template>
  710.     </xsl:template>
  711.  
  712.     <!-- Print a list                                                     -->
  713.     <xsl:template name="print-list">
  714.         <xsl:param name="operator" select="','"/>
  715.         <xsl:param name="value-node" select="."/>
  716.  
  717.         <xsl:for-each select="$value-node">
  718.             <xsl:apply-templates select="."/>
  719.             <xsl:if test="position()!=last()">
  720.                 <xsl:value-of select="$operator"/>
  721.             </xsl:if>
  722.         </xsl:for-each>
  723.     </xsl:template>
  724.  
  725.     <!-- Get the value of a parameter ref for the query                   -->
  726.     <xsl:template name="print-non-parametric-parameter-ref">
  727.         <xsl:param name="parameter-reference"/>
  728.  
  729.         <xsl:variable name="reference"><xsl:value-of select="$parameter-reference/@ref"/></xsl:variable>
  730.         <xsl:call-template name="print-non-parametric-parameter">
  731.             <xsl:with-param name="parameter" select="/Statement/Parameters/Parameter[@id=$reference]"/>
  732.         </xsl:call-template>
  733.     </xsl:template>
  734.  
  735.     <!-- Get the value of a parameter ref for the query                   -->
  736.     <xsl:template name="print-non-parametric-parameter">
  737.         <xsl:param name="parameter"/>
  738.  
  739.         <xsl:variable name="db-type"><xsl:value-of select="$parameter/@DBTYPE"/></xsl:variable>
  740.         <xsl:variable name="value"><xsl:value-of select="$parameter/text()"/></xsl:variable>
  741.         <xsl:choose>
  742.             <xsl:when test="$db-type = 'DBTYPE_BSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  743.             <xsl:when test="$db-type = 'DBTYPE_WSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  744.             <xsl:when test="$db-type = 'DBTYPE_STR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  745.             <xsl:when test="$db-type = 'DBTYPE_BOOL'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS bit)</xsl:when>
  746.             <xsl:when test="$db-type = 'DBTYPE_I1'"><xsl:value-of select="$value"/></xsl:when>
  747.             <xsl:when test="$db-type = 'DBTYPE_I2'"><xsl:value-of select="$value"/></xsl:when>
  748.             <xsl:when test="$db-type = 'DBTYPE_I4'"><xsl:value-of select="$value"/></xsl:when>
  749.             <xsl:when test="$db-type = 'DBTYPE_I8'"><xsl:value-of select="$value"/></xsl:when>
  750.             <xsl:when test="$db-type = 'DBTYPE_UI1'"><xsl:value-of select="$value"/></xsl:when>
  751.             <xsl:when test="$db-type = 'DBTYPE_UI2'"><xsl:value-of select="$value"/></xsl:when>
  752.             <xsl:when test="$db-type = 'DBTYPE_UI4'"><xsl:value-of select="$value"/></xsl:when>
  753.             <xsl:when test="$db-type = 'DBTYPE_UI8'"><xsl:value-of select="$value"/></xsl:when>
  754.             <xsl:when test="$db-type = 'DBTYPE_R4'"><xsl:value-of select="$value"/></xsl:when>
  755.             <xsl:when test="$db-type = 'DBTYPE_R8'"><xsl:value-of select="$value"/></xsl:when>
  756.             <xsl:when test="$db-type = 'DBTYPE_DATE'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  757.             <xsl:when test="$db-type = 'DBTYPE_DBTIMESTAMP'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  758.             <xsl:when test="$db-type = 'DBTYPE_CY'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS money)</xsl:when>
  759.             <xsl:when test="$db-type = 'DBTYPE_VARIANT'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  760.             <xsl:when test="$db-type = 'DBTYPE_GUID'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  761.             <xsl:when test="$db-type = 'DBTYPE_ByteArray'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  762.             <xsl:when test="$db-type = 'DBTYPE_DECIMAL'"><xsl:value-of select="$value"/></xsl:when>
  763.         </xsl:choose>
  764.     </xsl:template>
  765. </xsl:stylesheet>
  766.